<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8"> 
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
        <meta name="apple-mobile-web-app-capable" content="yes" />

        <!-- Base Css Files -->
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/jqueryui/ui-lightness/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/fontello/css/fontello.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/animate-css/animate.min.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/nifty-modal/css/component.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/magnific-popup/magnific-popup.css" rel="stylesheet" /> 
        <link href="__PUBLIC__/statics/coco-chat/assets/css/style.css" rel="stylesheet" type="text/css" />
        <link href="__PUBLIC__/statics/coco-chat/assets/css/style-responsive.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/pace/pace.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/jquery-notifyjs/styles/metro/notify-metro.css" rel="stylesheet" type="text/css" />
        
        <!-- Extra CSS Files -->
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap-select/bootstrap-select.min.css" rel="stylesheet" type="text/css" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap-validator/css/bootstrapValidator.min.css" rel="stylesheet"/>
        
        <!-- Custom Css Files -->
        <link href="__ADMIN_CSS__/style.css"  rel="stylesheet" />
    </head>
    
    <body>
    <!-- Begin page -->
	<div>
		<div class="sub-header-title">
			<h2>发布公告</h2>
		</div>
		<form role="form" id="add-form" class="form-horizontal" method="post" action="{:U('News/add')}">
		    <div class="form-group">
				<label for="input-category" class="col-sm-2 control-label"><span class="red_star">*</span>分类</label>
				<div class="col-sm-5">
				  <select class="form-control selectpicker" name="news_category_id">
					  <volist name="categorys" id="vo">
						  <option value="{$vo.id}">{$vo.title}</option>
					  </volist>
				  </select>
				</div>
			</div>
		  	<div class="form-group">
				<label for="input-title" class="col-sm-2 control-label"><span class="red_star">*</span>标题</label>
				<div class="col-sm-5">
				  	<input type="text" class="form-control" id="input-title" name="title">
				</div>
				<div class="col-sm-5">
					<p class="help-block">必须在2~50个字符之间</p>
				</div>
			</div>
			<div class="form-group">
				<label for="input-content" class="col-sm-2 control-label"><span class="red_star">*</span>内容</label>
				<div class="col-sm-5">
					<textarea id="editor" type="text/plain" style="height:300px;" name="content"></textarea>
				</div>
				<div class="col-sm-5">
					<p class="help-block">不允许为空</p>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-offset-4 col-sm-4">
                    <button type="submit" class="btn btn-success">添加</button>
                </div>
			</div>
		</form>
	</div>
	<!-- End of page -->
	
	<!-- Base Js Files -->
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery/jquery-1.11.1.min.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap/js/bootstrap.min.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jqueryui/jquery-ui-1.10.4.custom.min.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery-ui-touch/jquery.ui.touch-punch.min.js"></script>
 	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery-detectmobile/detect.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/fastclick/fastclick.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery-slimscroll/jquery.slimscroll.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/nifty-modal/js/classie.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/nifty-modal/js/modalEffects.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery-notifyjs/notify.min.js"></script>
    <script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery-notifyjs/styles/metro/notify-metro-blue.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/pace/pace.min.js"></script>
	
	<!-- Extra Js Files -->
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/statics/coco-chat/assets/libs/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/statics/coco-chat/assets/libs/ueditor/ueditor.all.js"></script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/statics/coco-chat/assets/libs/ueditor/lang/zh-cn/zh-cn.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap-validator/js/bootstrapValidator.min.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap-select/bootstrap-select.min.js"></script>
    <script src="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap-select2/select2.min.js"></script>
	
	<!-- Custom Js Files -->
	<script src="__ADMIN_JS__/common.js"></script>
	<script>
		var ue = UE.getEditor('editor',{
	       toolbars: [
          [
            'undo', //撤销
            'redo', //重做
            'bold', //加粗
            'italic', //斜体
            'underline', //下划线
            'forecolor', //字体颜色
            'strikethrough', //删除线
            'subscript', //下标
            'fontborder', //字符边框
            'superscript', //上标
            'formatmatch', //格式刷
            'customstyle', //自定义标题
            'paragraph', //段落格式
            'fontfamily', //字体
            'fontsize', //字号
            'pasteplain', //纯文本粘贴模式
            'selectall', //全选
            'removeformat', //清除格式
            'simpleupload', //单图上传
            'justifyleft', //居左对齐
            'justifyright', //居右对齐
            'justifycenter', //居中对齐
            'justifyjustify', //两端对齐
            'backcolor', //背景色
            'rowspacingtop', //段前距
            'rowspacingbottom', //段后距
            'lineheight', //行间距
            'edittip ', //编辑提示
          ]
        ],
        autoHeightEnabled: true,
        autoFloatEnabled: true,
        elementPathEnabled: false, //删除元素路径
	    });
		
		//SELECT
        $('.selectpicker').selectpicker();
		
        ue.addListener( 'contentChange', function( content ) {
            if (ue.getContentLength(true)>0) {
            	$('#add-form').data('bootstrapValidator').updateElementStatus($('#add-form').find("textarea[name='content']"), "VALID", null );
            } else {
            	$('#add-form').data('bootstrapValidator').updateElementStatus($('#add-form').find("textarea[name='content']"), "INVALID", null );
            }
        });
		
        $('#add-form').bootstrapValidator({
	        message: '',
	        trigger: 'blur',
	        excluded: [':disabled'],//[':disabled', ':hidden', ':not(:visible)']
	        submitHandler: function(validator, form, submitButton) {
	        	//询问框
				window.parent.layer.confirm('确定发布公告吗？', {
					btn: ['确认','取消'], //按钮
				    cancel: function(index){ 
				    	window.parent.layer.close(index);
						$("#add-form").bootstrapValidator('disableSubmitButtons', false);
					}
				}, function(index){
					// 用ajax提交表单
			      	$.post(form.attr('action'), form.serialize(), function(response) {
			      		//弹出提示
						window.parent.layer.msg(response.message);
			      		
			      		//根据请求相应状态提示通知
			       		if(response.status){
			       			notify("success",response.message);
			       			window.location.href = "{:U('News/index')}";
						}else{
							notify("error",response.message);
						}
			        }, 'json');
			      	window.parent.layer.close(index);
				}, function(index){
					window.parent.layer.close(index);
					$("#add-form").bootstrapValidator('disableSubmitButtons', false);
				});
	        },
	        fields: {
	        	title: {
	            	validators: {
	            		notEmpty: {
	                    },
	                    stringLength: {
	                        min: 2,
	                        max: 50,
	                    }
	                }
	            },
	            news_category_id: {
	            	validators: {
	            		notEmpty: {
	                    }
	                }
	            },
	            content: {
	            	validators: {
	            		notEmpty: {
	                    }
	                }
	            }
	        }
	    });
	</script>
	<style type="text/css">
     #edui1{z-index: 0 !important}
	</style>
	</body>
</html>